if(SERVER) then --- Caused errors on client

local loaded =  false

local Anomalies = { --you can comment out some of the types of anomalies to stop them from spawning automaticly
	"sent_spaceanon_nebula",
	"sent_spaceanon_ion_storm",
//	"sent_spaceanon_hypermass",
///	"sent_spaceanon_spore_cloud",
	"sent_spaceanon_asteroid_field",
	"sent_spaceanon_wormhole",
//	"sent_spaceanon_nullenergyfield"
	}
local Anon_Rad = { --you can comment out some of the types of anomalies to stop them from spawning automaticly
	1840,
	1790,
//	2000,
//	1000,
	1500,
	1850,
//	2048
	}
local anons = {}


function CreateAnomalies()
	local anonstospawn = 2+math.random(1,3)
	for i=1,anonstospawn do
		local rnd = math.random(1,table.maxn(Anomalies))
		Msg(Anomalies[rnd].."\n")
		local anon = ents.Create(Anomalies[rnd])
		anon:SetPos(VectorRand()*16384)--Please work better then the clamped random
		//anon:SetPos(Vector(math.random(-65530,65530),math.random(-65530,65530),math.random(-65530,65530)))
		anon:Spawn()
		while true do	
			local inplanet = false
			if planets then
				inplanet = true
				for _, p in pairs(planets) do
					if not (anon:GetPos():Distance(p.pos) < p.radius+Anon_Rad[rnd]+1000) then
						inplanet = false
					end
				end
			end
			if anon:IsInWorld() and not inplanet then
				if not (rnd == 4) then
					table.insert(anons, anon)
				else
					anon:Start()
				end
				break
			else
				anon:SetPos(VectorRand()*16384)--Please work better then the clamped random
				//anon:SetPos(Vector(math.random(-65530,65530),math.random(-65530,65530),math.random(-65530,65530)))
			end
		end
	end
end

function LOLWAT()
	for k,v in pairs(anons) do
		if v and v:IsValid() then
			v:Remove()
		end
	end
	anons = {}
	CreateAnomalies()
end
concommand.Add( "anons_new", LOLWAT)

function WATLOL()
for k,v in pairs(anons) do
		if v and v:IsValid() then
			v:Remove()
		end
	end
end
concommand.Add( "anons_clear", WATLOL)

if(SERVER)then
	local map = string.lower(game.GetMap())
	if string.find(map, "sb") or string.find(map,"space") or string.find(map, "rc1") then
		timer.Simple(2, CreateAnomalies)
		timer.Simple(10, AnonThink)
	end
end

local NT = 0
function AnonThink()
	if math.random(1,100) == 1 then
		local flare = ents.Create("sent_spaceanon_solar_flare")--Deargod it will KILL US ALL!
		flare:Spawn()
	end
//	if NT < CurTime() then
//		local a = ents.Create("sent_spaceanon_microasteroids")
//		a:Spawn()
//		NT = CurTime()+1
//	end
end
end